﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace TileMapEditor.TileEngine
{
    public class Layer
    {
        #region Attributes

        private Tile[,] tiles;
        private string name;
        private bool isVisible;

        #endregion

        #region Properites

        public Tile[,] Tiles
        {
            get { return tiles; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public bool IsVisible
        {
            get { return isVisible; }
            set { isVisible = value; }
        }

        #endregion

        /// <summary>
        /// Creates a blank layer
        /// </summary>
        public Layer(string name, int width, int height)
        {
            //Initialize tile array
            tiles = new Tile[height, width];
            isVisible = true;
        }

        /// <summary>
        /// Creates layer based on passed in Tile[,]
        /// </summary>
        public Layer(string name, Tile[,]layer) 
        {
            tiles = (Tile[,])layer.Clone();
            isVisible = true;
        }


        public virtual void Draw(SpriteBatch spriteBatch, Camera cam, MouseState curState, MouseState prevState) 
        {
            //row
            for (int y = 0; y < tiles.GetLength(0); y++) 
            {
                //col
                for (int x = 0; x < tiles.GetLength(1); x++)
                {
                    //Calls tile update
                    tiles[y, x].Update(cam,curState,prevState);

                    //Calls tile draw and renders the tile
                    tiles[y,x].Draw(spriteBatch);
                }
            }
        }

    }
}
